<script setup lang="ts">
import useCategory from '@/composables/category/useCategory';
import useTable from '@/composables/category/useTable';
import { Close, Delete, Edit, Plus, Search } from '@element-plus/icons-vue';
const { listParam, getList, searchBtn, resetBtn, tableList, sizeChange, currentChange ,tableHeight} = useTable()
//增删改业务
const { addBtn, deleteBtn, editBtn, addRef } = useCategory(getList)
//引入弹窗
import AddCategory from "@/views/category/AddCategory.vue";
//分页事件
</script>

<template>
    <el-main>
        <!-- 搜索框 -->
        <el-form :model="listParam" :inline="true" size="default">
            <el-form-item>
                <el-input v-model="listParam.categoryName" placeholder="请输入分类名称"> </el-input>
            </el-form-item>
            <el-form-item>
                <el-button :icon="Search" @Click="searchBtn">搜索</el-button>
                <el-button :icon="Close" type="danger" plain @Click="resetBtn">重置</el-button>
                <el-button :icon="Plus" type="primary" @click="addBtn">新增</el-button>
            </el-form-item>
        </el-form>
        <el-table :height="tableHeight" :data="tableList" border stripe>
            <el-table-column prop="categoryName" label="分类名称"></el-table-column>
            <el-table-column prop="orderNum" label="序号"></el-table-column>
            <el-table-column label="操作" width="250" align="center">
                <template #default="scope">
                    <el-button :icon="Edit" type="primary" size="default" @click="editBtn(scope.row)">编辑</el-button>
                    <el-button :icon="Delete" type="danger" size="default" @click="deleteBtn(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination 
        @size-change="sizeChange"
         @current-change="currentChange"   
        :current-page.sync="listParam.currentPage" 
        layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[10, 20, 40, 80, 100]" :page-size="listParam.pageSize" 
        :total="listParam.total" background>
        </el-pagination>
 
   


    </el-main>

    <!-- 新增、编辑弹框 -->
    <AddCategory ref="addRef" @onFresh="getList"></AddCategory>

</template>

<style scoped></style>